﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using eTMS.Commons;
using eTMS.Controllers;
using eTMS.Controllers.LyLichSinhVienService;
using eTMS.Forms;

namespace eTMS.UserControls
{
    public partial class LyLichSinhVienInfo : eTMS.Controls.UserControlBase
    {
        public LyLichSinhVienInfo()
        {
            InitializeComponent();
        }
        private void LoadLanguage()
        {
            labelTruongTuyenSinh.Text = LyLichSinhVienStringMapping.TruongTuyenSinh;
            labelDiaChiThuongTru.Text = LyLichSinhVienStringMapping.DiaChiThuongTru;
            labelDiaChiHienTai.Text = LyLichSinhVienStringMapping.DiaChiHienTai;
            labelMaNganhDuTuyen.Text = LyLichSinhVienStringMapping.MaNganhDuTuyen;
            labelSoBaoDanh.Text = LyLichSinhVienStringMapping.SoBaoDanh;
            labelDiemDuTuyen.Text = LyLichSinhVienStringMapping.DiemDuTuyen;
            labelDiemThuong.Text = LyLichSinhVienStringMapping.DiemThuong;
            labelLop10.Text = LyLichSinhVienStringMapping.Lop10;
            labelLop11.Text = LyLichSinhVienStringMapping.Lop11;
            labelLop12.Text = LyLichSinhVienStringMapping.Lop12;
            labelNamTotNghiepPTTH.Text = LyLichSinhVienStringMapping.NamTotNghiepPTTH;
            labelKhenThuongKyLuat.Text = LyLichSinhVienStringMapping.KhenThuongKyLuat;
            labelTomTatQuaTrinhHocTap.Text = LyLichSinhVienStringMapping.TomTatQuaTrinhHocTap;
            labelNgayVaoDoan.Text = LyLichSinhVienStringMapping.NgayVaoDoan;
            labelNoiVaoDoan.Text = LyLichSinhVienStringMapping.NoiVaoDoan;
            labelNgayVaoDang.Text = LyLichSinhVienStringMapping.NgayVaoDang;
            labelNoiVaoDao.Text = LyLichSinhVienStringMapping.NoiVaoDao;
            labelBaoTin.Text = LyLichSinhVienStringMapping.BaoTin;
            labelHoTenCha.Text = LyLichSinhVienStringMapping.HoTenCha;
            labelNgaySinhCha.Text = LyLichSinhVienStringMapping.NgaySinhCha;
            labelNgheNghiepCha.Text = LyLichSinhVienStringMapping.NgheNghiepCha;
            labelHoTenMe.Text = LyLichSinhVienStringMapping.HoTenMe;
            labelNgaySinhMe.Text = LyLichSinhVienStringMapping.NgaySinhMe;
            labelNgheNghiepMe.Text = LyLichSinhVienStringMapping.NgheNghiepMe;
            labelAnhChiEmRuot.Text = LyLichSinhVienStringMapping.AnhChiEmRuot;
            labelVoHoacChong.Text = LyLichSinhVienStringMapping.VoHoacChong;
            labelDanToc_ID.Text = LyLichSinhVienStringMapping.DanToc_ID;
            labelDoiTuongTS_ID.Text = LyLichSinhVienStringMapping.DoiTuongTS_ID;
            labelKhuVuc_ID.Text = LyLichSinhVienStringMapping.KhuVuc_ID;
            labelQuocGia_ID.Text = LyLichSinhVienStringMapping.QuocGia_ID;
            labelTinhThanh_ID.Text = LyLichSinhVienStringMapping.TinhThanh_ID;
            labelTonGiao_ID.Text = LyLichSinhVienStringMapping.TonGiao_ID;
            labelXepLoaiPhoThong_ID.Text = LyLichSinhVienStringMapping.XepLoaiPhoThong_ID;
        }
        //Copy data from control in screen to object
        private void CopyFromSreen(LyLichSinhVienEntity o)
        {
            o.TruongTuyenSinh = Convert.ToString(txtTruongTuyenSinh.Text);
            o.DiaChiThuongTru = Convert.ToString(txtDiaChiThuongTru.Text);
            o.DiaChiHienTai = Convert.ToString(txtDiaChiHienTai.Text);
            o.MaNganhDuTuyen = Convert.ToString(txtMaNganhDuTuyen.Text);
            o.SoBaoDanh = Convert.ToString(txtSoBaoDanh.Text);
            o.DiemDuTuyen = (decimal)txtDiemDuTuyen.Value;
            o.DiemThuong = (decimal)txtDiemThuong.Value;
            o.Lop10 = Convert.ToString(txtLop10.Text);
            o.Lop11 = Convert.ToString(txtLop11.Text);
            o.Lop12 = Convert.ToString(txtLop12.Text);
            o.NamTotNghiepPTTH = (int)txtNamTotNghiepPTTH.Value;
            o.KhenThuongKyLuat = Convert.ToString(txtKhenThuongKyLuat.Text);
            o.TomTatQuaTrinhHocTap = Convert.ToString(txtTomTatQuaTrinhHocTap.Text);
            o.NgayVaoDoan = Convert.ToString(txtNgayVaoDoan.Text);
            o.NoiVaoDoan = Convert.ToString(txtNoiVaoDoan.Text);
            o.NgayVaoDang = Convert.ToString(txtNgayVaoDang.Text);
            o.NoiVaoDao = Convert.ToString(txtNoiVaoDao.Text);
            o.BaoTin = Convert.ToString(txtBaoTin.Text);
            o.HoTenCha = Convert.ToString(txtHoTenCha.Text);
            o.NgaySinhCha = Convert.ToString(txtNgaySinhCha.Text);
            o.NgheNghiepCha = Convert.ToString(txtNgheNghiepCha.Text);
            o.HoTenMe = Convert.ToString(txtHoTenMe.Text);
            o.NgaySinhMe = Convert.ToString(txtNgaySinhMe.Text);
            o.NgheNghiepMe = Convert.ToString(txtNgheNghiepMe.Text);
            o.AnhChiEmRuot = Convert.ToString(txtAnhChiEmRuot.Text);
            o.VoHoacChong = Convert.ToString(txtVoHoacChong.Text);
            o.DanToc_ID = Convert.ToInt32(txtDanToc_ID.SelectedValue);
            o.DoiTuongTS_ID = Convert.ToInt32(txtDoiTuongTS_ID.SelectedValue);
            o.KhuVuc_ID = Convert.ToInt32(txtKhuVuc_ID.SelectedValue);
            o.QuanHuyen_ID = 0;
            o.QuocGia_ID = Convert.ToInt32(txtQuocGia_ID.SelectedValue);
            //o.SinhVien_ID = Convert.ToInt32(txtSinhVien_ID.SelectedValue);
            o.TinhThanh_ID = Convert.ToInt32(txtTinhThanh_ID.SelectedValue);
            o.TonGiao_ID = Convert.ToInt32(txtTonGiao_ID.SelectedValue);
            o.XepLoaiPhoThong_ID = Convert.ToInt32(txtXepLoaiPhoThong_ID.SelectedValue);
            //o.SinhVien_ID = Convert.ToInt32(txtSinhVien_ID.SelectedValue);
        }
        //Validate all data from control in screen before Save data
        protected bool ValidateScreen()
        {
            bool result = true;
            if (txtTruongTuyenSinh.Text.Trim() == "")
            {
                errorProviderData.SetError(txtTruongTuyenSinh, Constants.MSS_ERROR_TEXT);
                result = false;
            }
            else
            {
                errorProviderData.SetError(txtTruongTuyenSinh, "");
            }
            if (txtDiaChiThuongTru.Text.Trim() == "")
            {
                errorProviderData.SetError(txtDiaChiThuongTru, Constants.MSS_ERROR_TEXT);
                result = false;
            }
            else
            {
                errorProviderData.SetError(txtDiaChiThuongTru, "");
            }
            if (txtMaNganhDuTuyen.Text.Trim() == "")
            {
                errorProviderData.SetError(txtMaNganhDuTuyen, Constants.MSS_ERROR_TEXT);
                result = false;
            }
            else
            {
                errorProviderData.SetError(txtMaNganhDuTuyen, "");
            }
            if (((txtDanToc_ID.SelectedIndex <= 0) && ((txtDanToc_ID.IsAddChooseItem) || (txtDanToc_ID.IsAddAllItem))) || (txtDanToc_ID.SelectedIndex < 0))
            {
                errorProviderData.SetError(txtDanToc_ID, Constants.MSS_ERROR_DROPDOWN);
                result = false;
            }
            else
            {
                errorProviderData.SetError(txtDanToc_ID, "");
            }
            if (((txtDoiTuongTS_ID.SelectedIndex <= 0) && ((txtDoiTuongTS_ID.IsAddChooseItem) || (txtDoiTuongTS_ID.IsAddAllItem))) || (txtDoiTuongTS_ID.SelectedIndex < 0))
            {
                errorProviderData.SetError(txtDoiTuongTS_ID, Constants.MSS_ERROR_DROPDOWN);
                result = false;
            }
            else
            {
                errorProviderData.SetError(txtDoiTuongTS_ID, "");
            }
            if (((txtKhuVuc_ID.SelectedIndex <= 0) && ((txtKhuVuc_ID.IsAddChooseItem) || (txtKhuVuc_ID.IsAddAllItem))) || (txtKhuVuc_ID.SelectedIndex < 0))
            {
                errorProviderData.SetError(txtKhuVuc_ID, Constants.MSS_ERROR_DROPDOWN);
                result = false;
            }
            else
            {
                errorProviderData.SetError(txtKhuVuc_ID, "");
            }

            if (((txtQuocGia_ID.SelectedIndex <= 0) && ((txtQuocGia_ID.IsAddChooseItem) || (txtQuocGia_ID.IsAddAllItem))) || (txtQuocGia_ID.SelectedIndex < 0))
            {
                errorProviderData.SetError(txtQuocGia_ID, Constants.MSS_ERROR_DROPDOWN);
                result = false;
            }
            else
            {
                errorProviderData.SetError(txtQuocGia_ID, "");
            }

            if (((txtTinhThanh_ID.SelectedIndex <= 0) && ((txtTinhThanh_ID.IsAddChooseItem) || (txtTinhThanh_ID.IsAddAllItem))) || (txtTinhThanh_ID.SelectedIndex < 0))
            {
                errorProviderData.SetError(txtTinhThanh_ID, Constants.MSS_ERROR_DROPDOWN);
                result = false;
            }
            else
            {
                errorProviderData.SetError(txtTinhThanh_ID, "");
            }
            if (((txtTonGiao_ID.SelectedIndex <= 0) && ((txtTonGiao_ID.IsAddChooseItem) || (txtTonGiao_ID.IsAddAllItem))) || (txtTonGiao_ID.SelectedIndex < 0))
            {
                errorProviderData.SetError(txtTonGiao_ID, Constants.MSS_ERROR_DROPDOWN);
                result = false;
            }
            else
            {
                errorProviderData.SetError(txtTonGiao_ID, "");
            }
            if (((txtXepLoaiPhoThong_ID.SelectedIndex <= 0) && ((txtXepLoaiPhoThong_ID.IsAddChooseItem) || (txtXepLoaiPhoThong_ID.IsAddAllItem))) || (txtXepLoaiPhoThong_ID.SelectedIndex < 0))
            {
                errorProviderData.SetError(txtXepLoaiPhoThong_ID, Constants.MSS_ERROR_DROPDOWN);
                result = false;
            }
            else
            {
                errorProviderData.SetError(txtXepLoaiPhoThong_ID, "");
            }
            if (!result)
            {
                ShowInfo(Constants.MSS_REQUIRE_FIELD);
            }
            return result;
        }
        private void CopyToSreen(LyLichSinhVienEntity o)
        {
            if (!o.IsNullTruongTuyenSinh)
            {
                txtTruongTuyenSinh.Text = Convert.ToString(o.TruongTuyenSinh);
            }
            if (!o.IsNullDiaChiThuongTru)
            {
                txtDiaChiThuongTru.Text = Convert.ToString(o.DiaChiThuongTru);
            }
            if (!o.IsNullDiaChiHienTai)
            {
                txtDiaChiHienTai.Text = Convert.ToString(o.DiaChiHienTai);
            }
            if (!o.IsNullMaNganhDuTuyen)
            {
                txtMaNganhDuTuyen.Text = Convert.ToString(o.MaNganhDuTuyen);
            }
            if (!o.IsNullSoBaoDanh)
            {
                txtSoBaoDanh.Text = Convert.ToString(o.SoBaoDanh);
            }
            if (!o.IsNullDiemDuTuyen)
            {
                txtDiemDuTuyen.Text = Convert.ToString(o.DiemDuTuyen);
            }
            if (!o.IsNullDiemThuong)
            {
                txtDiemThuong.Text = Convert.ToString(o.DiemThuong);
            }
            if (!o.IsNullLop10)
            {
                txtLop10.Text = Convert.ToString(o.Lop10);
            }
            if (!o.IsNullLop11)
            {
                txtLop11.Text = Convert.ToString(o.Lop11);
            }
            if (!o.IsNullLop12)
            {
                txtLop12.Text = Convert.ToString(o.Lop12);
            }
            if (!o.IsNullNamTotNghiepPTTH)
            {
                txtNamTotNghiepPTTH.Text = Convert.ToString(o.NamTotNghiepPTTH);
            }
            if (!o.IsNullKhenThuongKyLuat)
            {
                txtKhenThuongKyLuat.Text = Convert.ToString(o.KhenThuongKyLuat);
            }
            if (!o.IsNullTomTatQuaTrinhHocTap)
            {
                txtTomTatQuaTrinhHocTap.Text = Convert.ToString(o.TomTatQuaTrinhHocTap);
            }
            if (!o.IsNullNgayVaoDoan)
            {
                txtNgayVaoDoan.Text = Convert.ToString(o.NgayVaoDoan);
            }
            if (!o.IsNullNoiVaoDoan)
            {
                txtNoiVaoDoan.Text = Convert.ToString(o.NoiVaoDoan);
            }
            if (!o.IsNullNgayVaoDang)
            {
                txtNgayVaoDang.Text = Convert.ToString(o.NgayVaoDang);
            }
            if (!o.IsNullNoiVaoDao)
            {
                txtNoiVaoDao.Text = Convert.ToString(o.NoiVaoDao);
            }
            if (!o.IsNullBaoTin)
            {
                txtBaoTin.Text = Convert.ToString(o.BaoTin);
            }
            if (!o.IsNullHoTenCha)
            {
                txtHoTenCha.Text = Convert.ToString(o.HoTenCha);
            }
            if (!o.IsNullNgaySinhCha)
            {
                txtNgaySinhCha.Text = Convert.ToString(o.NgaySinhCha);
            }
            if (!o.IsNullNgheNghiepCha)
            {
                txtNgheNghiepCha.Text = Convert.ToString(o.NgheNghiepCha);
            }
            if (!o.IsNullHoTenMe)
            {
                txtHoTenMe.Text = Convert.ToString(o.HoTenMe);
            }
            if (!o.IsNullNgaySinhMe)
            {
                txtNgaySinhMe.Text = Convert.ToString(o.NgaySinhMe);
            }
            if (!o.IsNullNgheNghiepMe)
            {
                txtNgheNghiepMe.Text = Convert.ToString(o.NgheNghiepMe);
            }
            if (!o.IsNullAnhChiEmRuot)
            {
                txtAnhChiEmRuot.Text = Convert.ToString(o.AnhChiEmRuot);
            }
            if (!o.IsNullVoHoacChong)
            {
                txtVoHoacChong.Text = Convert.ToString(o.VoHoacChong);
            }
            if (!o.IsNullDanToc_ID)
            {
                txtDanToc_ID.SelectedValue = o.DanToc_ID;
            }
            else
            {
                txtDanToc_ID.SelectedValue = null;
            }
            if (!o.IsNullDoiTuongTS_ID)
            {
                txtDoiTuongTS_ID.SelectedValue = o.DoiTuongTS_ID;
            }
            else
            {
                txtDoiTuongTS_ID.SelectedValue = null;
            }
            if (!o.IsNullKhuVuc_ID)
            {
                txtKhuVuc_ID.SelectedValue = o.KhuVuc_ID;
            }
            else
            {
                txtKhuVuc_ID.SelectedValue = null;
            }

            if (!o.IsNullQuocGia_ID)
            {
                txtQuocGia_ID.SelectedValue = o.QuocGia_ID;
            }
            else
            {
                txtQuocGia_ID.SelectedValue = null;
            }

            if (!o.IsNullTinhThanh_ID)
            {
                txtTinhThanh_ID.SelectedValue = o.TinhThanh_ID;
            }
            else
            {
                txtTinhThanh_ID.SelectedValue = null;
            }
            if (!o.IsNullTonGiao_ID)
            {
                txtTonGiao_ID.SelectedValue = o.TonGiao_ID;
            }
            else
            {
                txtTonGiao_ID.SelectedValue = null;
            }
            if (!o.IsNullXepLoaiPhoThong_ID)
            {
                txtXepLoaiPhoThong_ID.SelectedValue = o.XepLoaiPhoThong_ID;
            }
            else
            {
                txtXepLoaiPhoThong_ID.SelectedValue = null;
            }
        }
        public void UpdateToScreen()
        {
            CopyToSreen(controller.LyLichSinhVienEntity);
        }
        public void UpdateToModel()
        {
            if(controller.LyLichSinhVienEntity==null)
                controller.LyLichSinhVienEntity =new LyLichSinhVienEntity();
            CopyFromSreen(controller.LyLichSinhVienEntity);
        }
        private SinhVienController controller;
        public void SetController(SinhVienController sinhVienController)
        {
            controller = sinhVienController;
        }

        private void LyLichSinhVienInfo_Load(object sender, EventArgs e)
        {
            LoadLanguage();
        }
    }
}
